package com.gblw.rjkf.pj.controller;


import com.gblw.rjkf.pj.entity.SysUserSign;
import com.gblw.rjkf.pj.service.SysUserSignService;
import com.gblw.rjkf.pj.mapper.SysUserSignMapper;
import com.gblw.rjkf.pj.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * SysUserSignController(SysUserSign)
 *
 * @author wj
 * @since 2024-09-01 15:47:24
 */
@Api(tags = {"SysUserSign"})
@RestController
@RequestMapping("sysUserSign")
public class SysUserSignController {

    /**
     * 服务对象
     */
    @Autowired
    private SysUserSignService sysUserSignService;
    @Resource
    private SysUserSignMapper sysUserSignMapper;



    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("通过主键查询单条数据")
    @GetMapping("getById/{id}")
    public Result selectOne(@PathVariable Serializable id) {
        return Result.success("查询成功", sysUserSignService.getById(id));
    }

    /**
     * 新增数据
     * @param sysUserSign 实体对象
     * @return 新增结果
     */
    @ApiOperation("新增数据")
    @PostMapping("/insert")
    public Result insert(@RequestBody SysUserSign sysUserSign) {
        boolean rs = sysUserSignService.save(sysUserSign);
        if (rs) {
            return Result.success("添加成功", "");
        } else {
            return Result.error("添加失败");
        }
    }

    /**
     * 修改数据
     * @param sysUserSign 实体对象
     * @return 修改结果
     */
    @ApiOperation("修改数据")
    @PostMapping("/update")
    public Result update(@RequestBody SysUserSign sysUserSign) {
        sysUserSignService.updateById(sysUserSign);
        return Result.success("修改成功", "");
    }

    /**
     * 批量删除数据
     * @param idList 主键集合
     * @return 删除结果
     */
    @ApiOperation("批量删除数据")
    @PostMapping("/delete")
    public Result delete(@RequestParam("idList") List<Serializable> idList) {
        int result = 0;
        if (idList != null && idList.size() > 0) {
            sysUserSignService.removeByIds(idList);
        }
        ;
        return Result.success("删除成功", "");
    }

    /**
     * 批量删除数据
     * @param id 主键
     * @return 删除结果
     */
    @ApiOperation("单个删除数据")
    @PostMapping("/delete/{id}")
    public Result delete(@PathVariable Serializable id) {
        sysUserSignService.removeById(id);
        return Result.success("删除成功", "");
    }
}
